package com.ctcemti.mdm.project.sys.controller;


import com.ctcemti.mdm.common.result.Result;
import com.ctcemti.mdm.common.result.ResultEnum;
import com.ctcemti.mdm.project.sys.entity.OperationLog;
import com.ctcemti.mdm.project.sys.service.IOperationLogService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 操作日志Controller
 * bxf
 * @author 
 * @date Tue Nov 12 10:28:50 CST 2019
 */
@Controller
@Api(value = "OperationLogController", description = "操作日志控制器类")
@RequestMapping("/system/operationlog")
public class OperationLogController
{

    @Autowired
    private IOperationLogService operationLogService;

    /**
     * 查询操作日志对象
     */
    @PostMapping("/query")
    @ResponseBody
    public Result<OperationLog> query(HttpServletRequest request, HttpServletResponse response ,Long id)
    {
        OperationLog operationLog = operationLogService.selectOperationLogById(id);
        return new Result<OperationLog>(ResultEnum.SUCCESS,operationLog);
    }

    /**
     * 查询操作日志列表
     */
    @PostMapping("/list")
    @ResponseBody
    public Result<PageInfo<OperationLog>> queryList(HttpServletRequest request, HttpServletResponse response ,OperationLog operationLog)
    {
        PageInfo<OperationLog> pageInfo = operationLogService.selectOperationLogList(operationLog);
        return new Result<PageInfo<OperationLog>>(ResultEnum.SUCCESS,pageInfo);
    }



    /**
     * 新增保存操作日志
     */
    @PostMapping("/add")
    @ResponseBody
    public Result<OperationLog> insertOperationLog(HttpServletRequest request, HttpServletResponse response ,OperationLog operationLog)
    {
         operationLogService.insertOperationLog(operationLog);
         return new Result<OperationLog>(ResultEnum.SUCCESS,null);
    }

    /**
     * 修改操作日志
     */
    @PostMapping("/update")
    @ResponseBody
    public Result<OperationLog> updateOperationLog(HttpServletRequest request, HttpServletResponse response,  OperationLog operationLog)
    {
        operationLogService.updateOperationLog(operationLog);
        return new Result<OperationLog>(ResultEnum.SUCCESS,null);
    }


    /**
     * 删除操作日志
     */
    @PostMapping("delete")
    @ResponseBody
    public Result<OperationLog> remove(HttpServletRequest request, HttpServletResponse response ,String ids)
    {
        operationLogService.deleteOperationLogByIds(ids);
        return new Result<OperationLog>(ResultEnum.SUCCESS,null);
    }


    @PostMapping("common/download/downWorkbook")
    public void downWorkbook(HttpServletRequest request, HttpServletResponse response,String filename) throws Exception {
        operationLogService.uploadFile(response,request,filename);

    }

}
